package springboot.demo.shiro.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import springboot.demo.shiro.entity.dto.ResultDto;
import springboot.demo.shiro.entity.po.User;

/**
 * <p>Project: springboot-demo </p>
 * 
 * <p>Function:  </p>
 * 
 * <p>Description:  </p>
 * 
 * @author weiqiang.li
 * 
 * @date 2018/11/24
 * 
 * @version 1.0
 */
@RestController
public class LoginController {

    @PostMapping("/login")
    public ResultDto<?> login(@RequestBody User user) {
        Subject subject = SecurityUtils.getSubject();
        subject.login(new UsernamePasswordToken(user.getName(), user.getPassword()));
        return ResultDto.builder().success(true).build();
    }
}
